<?php
chdir("../");
header("content-type: text/html; charset=utf-8");
require "../config/config.php";
require "../config/attributes.php";
require GALAXYTOOL_ROOT."/secret/includes/authorization.inc.php";
session_start();
$NO_PAGE_FORWARD = true;
require GALAXYTOOL_ROOT."/secret/includes/logincheck.inc.php";
if (isset($error_page_code) && $error_page_code == "timeout") exit("");

if (!isset($_SESSION['lang'])) $_SESSION['lang'] = $default_language;
Galaxytool::load_language_file($_SESSION['lang']);

if ($_SESSION['s_auth']->get_permission(iAuthorization::permission_probeview) !== true) exit("no permission");

if (!isset($_GET['type'])) exit("");

require GALAXYTOOL_ROOT."/secret/includes/report_archive.inc.php";
$archive_obj = new ReportArchive($global_mysql_con,$reportarchive,$playertable);


$type = $_GET['type'];

switch ($type) {
	case "empty":
		// return no content as json format
		header("Content-type: application/json");
		header("Pragma: no-cache");
		header("Expires: 0");

		echo $archive_obj->get_empty();

		break;

	case "coordinates":
		header("content-type: text/html; charset=utf-8");
		header("Pragma: no-cache");
		header("Expires: 0");

		if (!isset($_GET['coordinates']) || !(preg_replace("/\d+\:\d+\:\d+/","",$_GET['coordinates']) == "")) exit("coordinates error");
		$coordinates = $_GET['coordinates'];
		$moon        = (isset($_GET['moon']) && $_GET['moon'] == "true") ? "true" : "false";

		require_once GALAXYTOOL_ROOT."/secret/includes/general.inc.php"; // loaded from plugins
		$probe_helper = new ProbeLanguages();
		$flipped_probe_array = $probe_helper->get_flipped_probe_array();
		$flipped_top_array   = $probe_helper->get_flipped_top_array();

		echo $archive_obj->get_coordinates($coordinates, $moon, $flipped_probe_array, $flipped_top_array);
		break;

	case "delete":
		header("content-type: text/html; charset=utf-8");
		header("Pragma: no-cache");
		header("Expires: 0");
		if ($_SESSION['s_auth']->get_permission(iAuthorization::permission_candelete) !== true) exit("no permissions");

		if (!isset($_POST['msg_id'])) exit("no msg id");
		$msg_ids = $_POST['msg_id'];
		$msg_ids = explode(",",$msg_ids);

		$result = $archive_obj->delete_reports($msg_ids);

		$messages = $archive_obj->get_error_object();
		$message_json = ($messages != null) ? $messages->get_JSON_result() : "null";
		$result = '{ result: '.json_encode($result).' , messages: '.$message_json.' }';
		exit($result);

		break;

}

?>